package com.doctor.comm;

import com.doctor.ui.R;

import android.app.ProgressDialog;
import android.content.Context;
import android.widget.Toast;

public class LoadingTip {

	private static ProgressDialog dialog;
	//上次Toast的时间
	private static long preTime = 0L;
	//上次Toast的内容
	private static String preContent = "";
	
	
	public static void showDialog(Context context,String tip){
		if (dialog!=null) {
			dialog.dismiss();
		}
		dialog=new ProgressDialog(context, R.style.common_dialog);
		dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		if (tip!=null && !"".equals(tip.trim())) {
			dialog.setMessage(tip);
		} else {
			dialog.setMessage("正在加载数据...");
		}
		dialog.setCancelable(false);
		dialog.show();
	}
	
	public static void setDialogMessage(String message) {
		if (dialog != null && dialog.isShowing()) {
			dialog.setMessage(message);
		}
	}
	
	public static void hideDialog(){
		if (dialog!=null && dialog.isShowing()) {
			dialog.dismiss();
			dialog=null;
		}
	}
	
	
	/**
	 * 在指定时间内不会重复出现相同内容的Toast
	 * @param context
	 * @param infoStr
	 */
	public static void showToast(Context context, String infoStr){
		long nowTime = System.currentTimeMillis();
		long duration = nowTime - preTime;
		if (duration < 2000 && preContent.equals(infoStr)) {
			return;
		}
		Toast.makeText(context, infoStr, Toast.LENGTH_SHORT).show();
		preTime = nowTime;
		preContent = infoStr;
	}
		
}
